package com.itheima.service;

import com.itheima.mapper.UserMapper;
import com.itheima.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class UserService {

    @Autowired
    private UserMapper userMapper;

    @Transactional
    public List<User> findAll(){
        //查询所有
      return userMapper.selectAll();
    }
    @Transactional
    public User findById(long id){
        //根据id查询
    return userMapper.selectByPrimaryKey(id);
    }

    @Transactional
    public void add(User user){
        System.out.println("新增用户...");
        userMapper.insertSelective(user);
    }
    @Transactional
    public void deleteById(long id){
        //根据id删除
        userMapper.deleteByPrimaryKey(id);
    }
    @Transactional
    public void update(User user){
        userMapper.updateByPrimaryKeySelective(user);
    }
}
